package pipe

import (
	"gitee.com/injoyai/goutil/cfg"
	"gitee.com/injoyai/goutil/conv"
	"gitee.com/injoyai/goutil/g"
	"gitee.com/injoyai/goutil/string/logs/v1"
	"log"
	"runtime"
)

func DemoServerTCP() {
	s, err := NewServerTCP(cfg.GetInt("port", 10000))
	if err != nil {
		logs.Err(err)
		return
	}
	for _, v := range cfg.GetStrings("listen") {
		m := conv.NewMap(v)
		s.Listen(m.GetInt("port"),
			m.GetString("sn"),
			m.GetString("addr"))
	}
	s.Run()
}

func DemoClient() {
	addr := cfg.GetString("addr", "121.36.99.197:9000")
	sn := cfg.GetString("sn", "test")
	c := NewClient(addr, sn)
	redirect := cfg.GetMap("redirect")
	if runtime.GOOS == "windows" && redirect["*"] == nil {
		s := g.Input("请输入代理地址(127.0.0.1:80)(默认代理全部):")
		redirect["*"] = s
	}
	for i, v := range redirect {
		c.Redirect(i, conv.String(v))
	}
	log.Printf("[信息][%s] 代理成功...", sn)
	c.Debug()
	c.Wait()
	select {}
}
